package edu.unc.comp410.colemangeer.model.constraints;

import org.apache.log4j.Logger;

import edu.unc.comp410.sharedcode.ValidateUtilities;


/**
 *  A required String must have visible content.
 *  "", "  " and the like are treated as <CODE>null</CODE>.
 */
public class StringConstraint extends ObjectConstraint {
	private static Logger log = Logger.getLogger( StringConstraint.class );

	public StringConstraint( String theName, boolean theOptional ) {
		super( theName, theOptional, String.class );
	}
	
	@Override public boolean isLegal( Object theObject ) {
		boolean validObject = super.isLegal( theObject );
		String str = (String) theObject;
		log.debug( str );
		if( ! isOptional() ) 
			validObject = ValidateUtilities.textHasContent( str );
		return validObject;
	}
	
}
